package hlhj.fhp.burst.adapter

import android.content.Context
import android.support.v4.view.PagerAdapter
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import com.bumptech.glide.Glide
import hlhj.fhp.burst.Contents
import hlhj.fhp.burst.GlideUtil
import hlhj.fhp.burst.R
import hlhj.fhp.burst.bean.BurstListBean
import java.util.ArrayList

/**
 * Created by Administrator on 2018\5\17 0017.
 */
class Vpadp(private val context:Context,private val datas:ArrayList<BurstListBean.DataBean.BannerBean>) :PagerAdapter(){
    override fun isViewFromObject(view: View, `object`: Any): Boolean {
        return view==`object`
    }

    override fun getCount(): Int {
        return Int.MAX_VALUE
    }

    override fun instantiateItem(container: ViewGroup, position: Int): Any {
        val inflater = LayoutInflater.from(context).inflate(R.layout.pager_item2, null)
        val img = inflater.findViewById<ImageView>(R.id.img)
        try {
            Glide.with(context).load(Contents.PUBLICK_URL+datas[position%datas.size].banner_img).apply(GlideUtil.loadImageOption()).into(img)
            container.addView(inflater)
        }catch (e:Exception){
            e.printStackTrace()
            Log.e("okgo","报错了${e.toString()}")
            Log.e("okgo","什么是空img空？${img==null}")
        }
        return inflater
    }

    override fun destroyItem(container: ViewGroup, position: Int, `object`: Any) {
//        super.destroyItem(container, position, `object`)
    }
}